# 地址：http://121.40.86.4:8899/admin/login
# 账号：admin
# 密码：Aa010903!
# 用例一：
# 1、用户登录
# 2、点击用户
# 3、点击用户分组
# 4、添加用户分组
# 5、判断添加是否成功
# 6、删除用户分组
# 7、判断删除是否是成功的
# 用例二：
# 1、登录
# 2、点击客服
# 3、客服话术
# 4、新增客服话术
# 5、看新增是否是成功的
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from ele import *
class CrmebGroup:
    def __init__(self,url,brwoser):
        self.brwoser = brwoser
        self.brwoser.get(url)
        self.brwoser.maximize_window()
        self.brwoser.implicitly_wait(15)
    def login(self,username,password):
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located(user_ele))[0].send_keys(username)
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located(pwd_ele))[1].send_keys(password)
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_element_located(lo_btn)).click()
    def add_group(self,groupName):
        self.groupName = groupName
        time.sleep(5)
        # 用户
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located(u_btn))[1].click()
        # 用户分组
        WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_element_located(userGroup_ele)).click()
        time.sleep(2)
        # 点击添加分组
        WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_element_located(add_group_ele)).click()
        # 等待弹窗弹出
        time.sleep(2)
        WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located(input_group_ele))[2].send_keys(self.groupName)
        # 点击确定按钮
        WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located(accept_ele))[2].click()
        # 等待新增
        time.sleep(3)
    def assert_add(self):
        # 判断是否添加成功
        text = WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_element_located((By.XPATH,f"//*[text()='{self.groupName}']"))).text
        assert text == self.groupName
    def delete_group(self):
        # 删除刚才新增过的
        WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located(delete_ele))[-1].click()
        # 点击删除确认按钮
        WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located(ele_accept_ele))[-1].click()
if __name__ == '__main__':
    driver = webdriver.Chrome()
    url = "http://121.40.86.4:8899/admin/login"
    c1 = CrmebGroup(url,driver)
    c1.login("admin","Aa010903!")
    c1.add_group("啊实打实的")
    c1.assert_add()
    c1.delete_group()


